package com.wash.shoes.common.serializer;

import java.io.IOException;
import java.util.List;
import java.util.Map;

import com.fasterxml.jackson.core.JsonGenerator;
import com.fasterxml.jackson.databind.JsonSerializer;
import com.fasterxml.jackson.databind.SerializerProvider;
import com.google.common.collect.Lists;
import com.wash.shoes.common.enums.FactoryServiceTypeEnum;

import cn.hutool.core.collection.CollectionUtil;

/**
 * 工厂服务类型枚举序列化
 */
public class ServiceTypeJsonSerializer extends JsonSerializer<List<FactoryServiceTypeEnum>> {

    @Override
    public void serialize(List<FactoryServiceTypeEnum> factoryServiceTypeEnums, JsonGenerator jsonGenerator,
        SerializerProvider serializerProvider) throws IOException {
        List<Map> data = Lists.newArrayList();
        if (CollectionUtil.isNotEmpty(factoryServiceTypeEnums)) {
            for (FactoryServiceTypeEnum factoryServiceTypeEnum : factoryServiceTypeEnums) {
                data.add(factoryServiceTypeEnum.toMap());
            }
        }
        jsonGenerator.writeObject(data);
    }
}
